package dao;


import util.DBTools;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

public class CommentDao {
    public int addComment(Integer uid, Integer aid, String content) {

        Connection connection = DBTools.getConnection();
        PreparedStatement ps = null;

        String sql = "insert into comment(uid,aid,content,addtime) values (?,?,?,?)";
        int total = 0;
        try {
            ps = connection.prepareStatement(sql);
            ps.setInt(1, uid);
            ps.setInt(2, aid);
            ps.setString(3, content);
            Date now = new Date();
            Timestamp addtime = new Timestamp(now.getTime());
            ps.setTimestamp(4, addtime);
            total = ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBTools.close(connection, ps, null);
        }
        return total;

    }
}